package com.shenbianyun.bosskgpay.utils;


import java.nio.charset.StandardCharsets;

/**
 * @date : 2025/2/25 20:40
 */
public class PasswordCheckUtils {

    public static String desDecrypt(String password) {

        long floor = (long) Math.floor((double) System.currentTimeMillis() / 60000);
        String passwordText = null;
        passwordText = desEncrypt(password, String.valueOf(floor));
        if (passwordText == null) {
            for (int i = 1; i <= 5; i++) {
                passwordText = desEncrypt(password, String.valueOf(floor - i));
                if (passwordText != null) {
                    return passwordText;
                }
                passwordText = desEncrypt(password, String.valueOf(floor + i));
                if (passwordText != null) {
                    return passwordText;
                }
            }
        }
        if (passwordText == null) {
            System.out.println("密码解密错误");
        }
        return passwordText;
    }

    public static String desEncrypt(String password, String floor) {
        try {
            byte[] s = DESUtils.decrypt(Base64Utils.decode(password), floor);
            return new String(s, StandardCharsets.UTF_8);
        } catch (Exception e) {
            return null;
        }
    }
}
